package com.lookoutthebush.companyindex.dao;

import com.lookoutthebush.companyindex.domain.UsersDO;
import com.lookoutthebush.companyindex.util.MyJdbcDAO;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Collections;

/**
 * 用户表
 *
 * @author LookOutTheBush
 * @date 2021/9/17 9:02 下午
 */
@Repository
public class UsersDAO {

    @Resource
    private MyJdbcDAO jdbcDAO;

    public Long insert(UsersDO usersDO) {
        jdbcDAO.create(usersDO);
        return usersDO.getId();
    }

    public UsersDO queryById(Long id){
        return jdbcDAO.queryById(id, UsersDO.class);
    }

    public UsersDO queryByUserName(String userName){
        String sql = "select * from users where username = :userName limit 1";
        return jdbcDAO.queryForObject(sql, Collections.singletonMap("userName", userName), UsersDO.class);
    }
}
